//https://blog.csdn.net/zl1zl2zl3/article/details/81357146
import { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Modal,
} from 'antd';

const FormItem = Form.Item;



// 修改表单
@Form.create()
class UpdateForm extends PureComponent {
    static defaultProps = {
        handleUpdate: () => {},
    handleUpdateModalVisible: () => {},
values: {},
};

constructor(props) {
    super(props);

    this.state = {
        formVals: {
                id: props.values.id,
                name: props.values.name,
                ename: props.values.ename,
                contextpath: props.values.contextpath,
                tableprefix: props.values.tableprefix,
                logo: props.values.logo,
                icon: props.values.icon,
                version: props.values.version,
                builddate: props.values.builddate,
                status: props.values.status,
                orderid: props.values.orderid,
                memo: props.values.memo,
        },
    };


}

 handleLocalUpdate = () => {
    const { form, handleUpdate } = this.props;
    const { formVals: oldValue } = this.state;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      const formVals = { ...oldValue, ...fieldsValue };
      this.setState(
        {
          formVals,
        }
      );
     
     handleUpdate(formVals);

    });
  };


renderContent = (formVals) => {
    const { form } = this.props;

    return (
        <Form  layout="vertical">



                <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

                    <Col  md={12} sm={24}>
		                    <FormItem  label="系统名称">
		                        {form.getFieldDecorator('name', {
		                        rules: [{ required: true, message: '请输入系统名称！', min: 1 }],
		                        initialValue: formVals.name,
		                        })(<Input placeholder="请输入" />)}
		                    </FormItem>
                    </Col>

                    <Col  md={12} sm={24}>
		                    <FormItem  label="英文名称">
		                        {form.getFieldDecorator('ename', {
		                        rules: [{ required: false, message: '请输入英文名称！', min: 1 }],
		                        initialValue: formVals.ename,
		                        })(<Input placeholder="请输入" />)}
		                    </FormItem>
                    </Col>



            		</Row>


            		<Row gutter={{ md: 8, lg: 24, xl: 48 }}>

                    <Col  md={12} sm={24}>
		                    <FormItem  label="系统标志">
		                        {form.getFieldDecorator('logo', {
		                        rules: [{ required: false, message: '请输入系统标志！', min: 1 }],
		                        initialValue: formVals.logo,
		                        })(<Input placeholder="请输入" />)}
		                    </FormItem>
                    </Col>

                    <Col  md={12} sm={24}>
		                    <FormItem  label="系统图标">
		                        {form.getFieldDecorator('icon', {
		                        rules: [{ required: false, message: '请输入系统图标！', min: 1 }],
		                        initialValue: formVals.icon,
		                        })(<Input placeholder="请输入" />)}
		                    </FormItem>
                    </Col>



              	</Row>

              	<Row gutter={{ md: 8, lg: 24, xl: 48 }}>


                    <Col  md={12} sm={24}>
		                    <FormItem  label="版本">
		                        {form.getFieldDecorator('version', {
		                        rules: [{ required: false, message: '请输入版本！', min: 1 }],
		                        initialValue: formVals.version,
		                        })(<Input placeholder="请输入" />)}
		                    </FormItem>
                    </Col>


                    <Col  md={12} sm={24}>
		                    <FormItem  label="状态">
		                        {form.getFieldDecorator('status', {
		                        rules: [{ required: false, message: '请输入状态！', min: 1 }],
		                        initialValue: formVals.status,
		                        })(<Input placeholder="请输入" />)}
		                    </FormItem>
                    </Col>


                </Row>

                    
                <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


                    <Col  md={12} sm={24}>
	                    <FormItem  label="排序">
	                        {form.getFieldDecorator('orderid', {
	                        rules: [{ required: false, message: '请输入排序！', min: 1 }],
	                        initialValue: formVals.orderid,
	                        })(<Input placeholder="请输入" />)}
	                    </FormItem>
                    </Col>



                    <Col  md={12} sm={24}>
	                    <FormItem  label="备注">
	                        {form.getFieldDecorator('memo', {
	                        rules: [{ required: false, message: '请输入备注！', min: 1 }],
	                        initialValue: formVals.memo,
	                        })(<Input placeholder="请输入" />)}
	                    </FormItem>
                    </Col>

                </Row>


    </Form>
);

};



render() {
    const { updateModalVisible, handleUpdateModalVisible, values} = this.props;
    const {  formVals } = this.state;

    return (
        <Modal
    width={800}
    height={800}
    bodyStyle={{ padding: '32px 40px 48px' }}
    destroyOnClose
    title="修改"
    visible={updateModalVisible}
    onOk={() => this.handleLocalUpdate()}
    onCancel={() => handleUpdateModalVisible(false, values)}
    afterClose={() => handleUpdateModalVisible()}
>

    {this.renderContent(formVals)}
</Modal>
);
}

}

export default UpdateForm;
